<?php


namespace app\middleware;

use app\BaseController;

use app\lib\exception\AuthException;
use app\lib\exception\ParamException;
use app\services\AuthService;
use think\facade\Cache;
use think\Request;

class JwtAuth extends BaseController
{
    public function handle(Request $request, \Closure $next, $role = null)
    {
        $token = $request->header('Authorization');



        $authService = new AuthService();

        $user = $authService->checkingRole($token, $role);

        if (empty($user))throw new AuthException('权限错误', self::AUTH_EXCEPTION);

//      验证通过,将得到的用户id,放到请求信息中去,方便后续使用
        $request->user = $user;

        return $next($request);
    }

}